package com.gem.factory.card;

import com.gem.entity.Card;
import com.gem.netty.entity.CardInfo;
import lombok.Data;

import javax.swing.plaf.PanelUI;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Author: Xhy
 * CreateTime: 2022-09-25 23:27
 * 卡牌库
 *
 */
@Data
public class CardBaseFactory {
    // key:房间id  value: 对应游戏中的牌库信息
    private static Map<String, Map<Integer, List<Card>>> cardBase = new HashMap<>();

    public static void put(String roomId,Map<Integer, List<Card>> cards){
        cardBase.put(roomId,cards);
    }

    public static void add(String roomId,Card card){
        Map<Integer, List<Card>> map = cardBase.get(roomId);
        List<Card> cardList = map.get(card.getType());
        cardList.add(card);
        Collections.shuffle(cardList);

    }

    public static Map<Integer, List<Card>> get(String roomId){
        return cardBase.get(roomId);
    }

    public static void remove(String roomId){
        cardBase.remove(roomId);
    }


    public static boolean existCard(String roomId, CardInfo cardType){
        List<Card> cardList = get(roomId).get(cardType.getType());

        return existCard(cardList,cardType.getNo());
    }

    private static boolean existCard(List<Card> cards,Integer no){
        for (Card card : cards) {
            if (card.getNo() == no){
                return true;
            }
        }
        return false;
    }
}
